<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<!DOCTYPE html>
<html>
<head>
	<title>下单</title>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<link href="${server}/static/css/bootstrap.min.css" rel="stylesheet">
	<link href="${server}/static/css/bootstrap_new.css" rel="stylesheet">
	<script type="text/javascript" src="${server}/static/js/jquery.min.js"></script>
	<script type="text/javascript" src="${server}/static/js/bootstrap.min.js"></script>
	<script type="text/javascript" src="${server}/static/js/bootstrap_new.js"></script>
	
	<script type="text/javascript">
	$(document).ready(function(){
		if('${message}' !='' && '${message}' !='null' ){
			 setMessage("alert-warning",'${message}');
		 }
	});
	function placeonorder(){
		var orders ="";
		var valiFlag = true;
		$("input[name=merchQty]").each(function(){
			var qty = $(this).val();
			var reg=new RegExp("^\\d*$");
			if(!reg.test(qty)){alert(qty);
				valiFlag = false;
			}
			var row = $(this).attr("id");
			if(qty!="")orders += row+":"+qty+"_";
		});
		if(!valiFlag||orders==""){
			 setMessage("alert-warning",'未填写数量或填写格式错误');
			 return;
		}
		setMessage("alert-warning",'订单生成中...');
		var url = "${server }/quotationorder/order/"+$('#quotationId').val();
		window.location.href = url+"?orders="+orders+"&pic_col=${pic_col}&qty_col=${qty_col}&retail_col=${retail_col}";
		window.setTimeout(function (){
   			window.location.href="${server }/quotationorder/list/"+$('#quotationId').val();
   		},2000);
	}
	function setMessage(classstr,message){
		$('#message').html(message);
		$('#messageDiv').attr("class","alert alert-dismissable").addClass(classstr);
		$('#messageDiv').show();
	}
	function orderQtyChange(row){
		var qty = $('#'+row).val();
		if('${retail_col}'!='-1'){
			var retail = $('#'+row+'retail').val();
			if(qty!=""&&retail!=""){
				$('#'+row+"totalRetail").val(Math.round(Number(qty)*Number(retail) * 100)/100);
			}
		}
	}
	</script>
</head>
<body data-spy="scroll" data-target=".navbar" data-offset="50">
	<%@include file="../common/header.jsp"%>
	<input type="hidden" id="quotationId" value="${quotationId}">
	<%-- <input type="hidden" id="qty_col" value="${qty_col}">
	<input type="hidden" id="pic_col" value="${pic_col}"> --%>
<form action="" id="pagerForm"  method="post">
	
	<div class="container">
		<div class="alert alert-danger alert-dismissable" id="messageDiv"  style="display: none;" >
			<button type="button" class="close" data-dismiss="alert" aria-hidden="true">
				&times;</button>
			<span id="message"></span>
		</div>
		<table class="table table-bordered table-hover  table-striped" contenteditable="true">
			<thead>
				<tr>
					<c:if test="${! empty titles}">
						<th style="min-width :60px">序号</th>
						<th style="min-width :60px">数量</th>
						<c:forEach  items="${titles}" var="title" varStatus="status">
							<th style="min-width :60px">${title}</th>
						</c:forEach>
						<th style="min-width :60px">Total_Retail</th>
					</c:if>
				</tr>
			</thead>
			<tbody>
				<c:if test="${! empty rows}">
					<c:forEach  items="${rows}" var="row" varStatus="status">
					<tr>
						<td>${status.index+1}</td>
						<td style="max-width :60px"><input name="merchQty" style="width:100%" id="${status.index+1}" value="" onchange="orderQtyChange(${status.index+1})"></td>
						<c:forEach  items="${row}" var="col" varStatus="statu">
							<c:if test="${statu.index == pic_col}">
								<td><c:if test="${! empty col}"><img src="/excelimg/${col}" width="100px"></c:if></td>
							</c:if>
							<c:if test="${statu.index != pic_col}">
								<td <c:if test="${fn:length(col)> 30}">style="min-width :200px"</c:if> >
									${col}
									<c:if test="${statu.index == retail_col}">
										<input type="hidden" id="${status.index+1}retail" value="${col}">
										</c:if>
								</td>
							</c:if>
						</c:forEach>
						<td><input style="width:100%" id="${status.index+1}totalRetail" value="" >
						</td>
					</tr>
					
					</c:forEach>
				</c:if>
			

			</tbody>
		</table>
			<div class="form-group">
				<div class="col-sm-offset-2 col-sm-10">
					<button type="button" class="btn  btn-primary"
						onclick="placeonorder()" contenteditable="true">生成订单</button>
					<button type="button" class="btn  btn-primary"
						onclick="javascript:window.location.href='${server }/quotation/list/';" contenteditable="true">返回</button>
				</div>
			</div>
		</div>
</form>


</body>
</html>
